//
//  HCMessageCenterViewController.m
//  HappyChildren
//
//  Created by WillyZhao on 2017/1/19.
//  Copyright © 2017年 WillyZhao. All rights reserved.
//

#import "HCMessageCenterViewController.h"

#import "HCMessageCenterView.h"

#import "HCMsgCenterModel.h"
#import "HCLogViewController.h"

@interface HCMessageCenterViewController () <HCMessageCenterViewClicked> {
    HCMessageCenterView *cView;
    HCMsgCenterModel *msgModel;
}

@end

@implementation HCMessageCenterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.textTitle = @"消息中心";
    
    self.dataRequest.delegate = self;
    
//    if ([PublicFunction isNull:HCGETUSER(@"userid")]) {
//        HCLogViewController *log = [[HCLogViewController alloc] init];
//        
//        UINavigationController *na = [[UINavigationController alloc] initWithRootViewController:log];
//        na.navigationBarHidden = YES;
//        [self.navigationController presentViewController:na animated:YES completion:nil];
//    }else{
        [self.dataRequest postHC_IndexMessage:HCGETUSER(@"userid")];
//    }
    
    cView = [[HCMessageCenterView alloc] initWithFrame:CGRectMake(0, 0, self.centerView.frame.size.width, self.centerView.frame.size.height)];
    cView.delegate = self;
    [self.centerView addSubview:cView];
    
}

#pragma mark HCMessageCenterViewClicked
-(void)messageCenterSystemClicked {
    //系统消息进入
    [self pushChildrenViewController:@"HCSystemMessageViewController" parameterObject:@"system" dataObject:nil];
}

-(void)messageCenterShopClicked {
    //店铺消息进入
    [self pushChildrenViewController:@"HCSystemMessageViewController" parameterObject:@"shop" dataObject:nil];
}

-(void)messageCenterCellClicked:(NSIndexPath *)indexPath {
    HCMsgCenterData *data = msgModel.message[indexPath.row];
    if ([data.name isEqualToString:@"系统消息"]) {
        [self pushChildrenViewController:@"HCSystemMessageViewController" parameterObject:@"system" dataObject:data];
    }else{
        [self pushChildrenViewController:@"HCSystemMessageViewController" parameterObject:@"shop" dataObject:data];
    }
}

-(void)dataRequesterFail:(DataRequester *)requester requesterWithType:(DataRequestType)aType receiveErrorDictionary:(NSDictionary *)dictionary {
    NSLog(@"消息中心失败");
}

-(void)dataRequesterFinish:(DataRequester *)requester requesterWithType:(DataRequestType)aType receiveDictionary:(NSDictionary *)dictionary {
    NSLog(@"消息中心:%@",dictionary);
    msgModel = [[HCMsgCenterModel alloc] initWithDictionary:dictionary error:nil];
    cView.model = msgModel;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
